/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package bmacotada.orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import bmacotada.orm.*;

public class Paciente_1DAOImpl implements bmacotada.orm.dao.Paciente_1DAO {
	public Paciente_1 loadPaciente_1ByORMID(int pa_id_paciente) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPaciente_1ByORMID(session, pa_id_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 getPaciente_1ByORMID(int pa_id_paciente) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getPaciente_1ByORMID(session, pa_id_paciente);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByORMID(int pa_id_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPaciente_1ByORMID(session, pa_id_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 getPaciente_1ByORMID(int pa_id_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return getPaciente_1ByORMID(session, pa_id_paciente, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByORMID(PersistentSession session, int pa_id_paciente) throws PersistentException {
		try {
			return (Paciente_1) session.load(bmacotada.orm.Paciente_1.class, new Integer(pa_id_paciente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 getPaciente_1ByORMID(PersistentSession session, int pa_id_paciente) throws PersistentException {
		try {
			return (Paciente_1) session.get(bmacotada.orm.Paciente_1.class, new Integer(pa_id_paciente));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByORMID(PersistentSession session, int pa_id_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Paciente_1) session.load(bmacotada.orm.Paciente_1.class, new Integer(pa_id_paciente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 getPaciente_1ByORMID(PersistentSession session, int pa_id_paciente, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Paciente_1) session.get(bmacotada.orm.Paciente_1.class, new Integer(pa_id_paciente), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1[] listPaciente_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listPaciente_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1[] listPaciente_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return listPaciente_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1[] listPaciente_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Paciente_1 as Paciente_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Paciente_1[]) list.toArray(new Paciente_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1[] listPaciente_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Paciente_1 as Paciente_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Paciente_1[]) list.toArray(new Paciente_1[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPaciente_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return loadPaciente_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Paciente_1[] paciente_1s = listPaciente_1ByQuery(session, condition, orderBy);
		if (paciente_1s != null && paciente_1s.length > 0)
			return paciente_1s[0];
		else
			return null;
	}
	
	public Paciente_1 loadPaciente_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Paciente_1[] paciente_1s = listPaciente_1ByQuery(session, condition, orderBy, lockMode);
		if (paciente_1s != null && paciente_1s.length > 0)
			return paciente_1s[0];
		else
			return null;
	}
	
	public static java.util.Iterator iteratePaciente_1ByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iteratePaciente_1ByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePaciente_1ByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = bmacotada.orm.Taller1BMPersistentManager.instance().getSession();
			return iteratePaciente_1ByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePaciente_1ByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Paciente_1 as Paciente_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iteratePaciente_1ByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From bmacotada.orm.Paciente_1 as Paciente_1");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 createPaciente_1() {
		return new bmacotada.orm.Paciente_1();
	}
	
	public boolean save(bmacotada.orm.Paciente_1 paciente_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().saveObject(paciente_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(bmacotada.orm.Paciente_1 paciente_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().deleteObject(paciente_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Paciente_1 paciente_1)throws PersistentException {
		try {
			bmacotada.orm.Cuestionario_1[] lCuestionario_1s = paciente_1.cuestionario_1.toArray();
			for(int i = 0; i < lCuestionario_1s.length; i++) {
				lCuestionario_1s[i].setPaciente_1Rut(null);
			}
			return delete(paciente_1);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(bmacotada.orm.Paciente_1 paciente_1, org.orm.PersistentSession session)throws PersistentException {
		try {
			bmacotada.orm.Cuestionario_1[] lCuestionario_1s = paciente_1.cuestionario_1.toArray();
			for(int i = 0; i < lCuestionario_1s.length; i++) {
				lCuestionario_1s[i].setPaciente_1Rut(null);
			}
			try {
				session.delete(paciente_1);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(bmacotada.orm.Paciente_1 paciente_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().refresh(paciente_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(bmacotada.orm.Paciente_1 paciente_1) throws PersistentException {
		try {
			bmacotada.orm.Taller1BMPersistentManager.instance().getSession().evict(paciente_1);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Paciente_1 loadPaciente_1ByCriteria(Paciente_1Criteria paciente_1Criteria) {
		Paciente_1[] paciente_1s = listPaciente_1ByCriteria(paciente_1Criteria);
		if(paciente_1s == null || paciente_1s.length == 0) {
			return null;
		}
		return paciente_1s[0];
	}
	
	public Paciente_1[] listPaciente_1ByCriteria(Paciente_1Criteria paciente_1Criteria) {
		return paciente_1Criteria.listPaciente_1();
	}
}
